package com.example.yls.demoa;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

import java.util.ArrayList;

public class AddActivity extends AppCompatActivity {
    private EditText add_name;
    private EditText add_age;
    private EditText add_no;
    private RadioButton radioBtn1;
    private RadioButton radioBtn2;
    private RadioButton radioBtn3;
    private Button btn_confirm_add;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        add_name = findViewById(R.id.add_name);
        add_age = findViewById(R.id.add_age);
        add_no = findViewById(R.id.add_no);
        radioBtn1 = findViewById(R.id.radioBtn1);
        radioBtn2 = findViewById(R.id.radioBtn2);
        radioBtn3 = findViewById(R.id.radioBtn3);

        btn_confirm_add = findViewById(R.id.btn_confirm_add);
        btn_confirm_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                  String name = add_name.getText().toString();
                  int age = Integer.parseInt(add_age.getText().toString());
                  int no  =Integer.parseInt(add_no.getText().toString());
                int imgId = R.drawable.dog1;

                if(radioBtn1.isChecked()){
                    imgId = R.drawable.dog1;
                }else if(radioBtn2.isChecked()){
                    imgId = R.drawable.dog2;
                }else if(radioBtn3.isChecked()){
                    imgId = R.drawable.dog3;
                }

                Intent intent = new Intent();
                intent.putExtra("NO",no);
                intent.putExtra("NAME",name);
                intent.putExtra("AGE",age);
                intent.putExtra("IMG",imgId);
                setResult(2001,intent);

                finish();
            }
        });
    }
}
